package com.business_clean.ui.activity.todo;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;

import com.blankj.utilcode.util.LogUtils;
import com.business_clean.R;
import com.business_clean.app.base.BaseAgentWebActivity;
import com.business_clean.app.config.OnJsBridge;
import com.business_clean.app.ext.CommonUtils;
import com.business_clean.app.network.NetUrl;
import com.business_clean.app.uitl.ActivityForwardUtil;
import com.business_clean.app.uitl.ToastUtil;
import com.business_clean.databinding.ActivityCompanyProjectBinding;
import com.business_clean.databinding.ActivityTodoDetailBinding;
import com.business_clean.ui.activity.personnel.PersonnelDetailActivity;
import com.just.agentweb.AgentWeb;
import com.just.agentweb.WebChromeClient;
import com.just.agentweb.WebViewClient;
import com.lxj.xpopup.XPopup;

import org.json.JSONObject;

import me.hgj.mvvmhelper.base.BaseViewModel;
import me.hgj.mvvmhelper.ext.LogExtKt;

public class TodoDetailActivity extends BaseAgentWebActivity<BaseViewModel, ActivityTodoDetailBinding> {

    private String application_type;
    private String application_no;

    @Override
    public void initView(Bundle savedInstanceState) {
        if (getIntent() != null && getIntent().getExtras() != null) {
            application_type = getIntent().getExtras().getString("application_type");
            application_no = getIntent().getExtras().getString("application_no");
        }
    }

    @Override
    public void onBindViewClick() {

    }

    @Override
    public void initObserver() {

    }


    @Override
    protected OnJsBridge getOnJsBridge() {
        return new JsBridge(mAgentWeb.get());
    }

    class JsBridge extends OnJsBridge {
        JsBridge(AgentWeb mAgentWeb) {
            super(mAgentWeb);
        }

        @SuppressLint("JavascriptInterface")
        @JavascriptInterface
        public void backPage() {
            finish();
        }

        @JavascriptInterface
        public void goDetail(String json) {
            LogUtils.e("json =" + json);
            try {
                if (!TextUtils.isEmpty(json)) {
                    JSONObject jsonObject = new JSONObject(json);
                    String uuid = jsonObject.optString("uuid");
                    Bundle bundle = new Bundle();
                    bundle.putString("uuid", uuid);
                    ActivityForwardUtil.startActivity(PersonnelDetailActivity.class, bundle);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    }


    @Override
    protected ViewGroup getAgentWebParent() {
        return mDatabind.llLayout;
    }

    @Override
    protected String getUrl() {
        return CommonUtils.getWebUrlHost() + NetUrl.WEB_TODO_DETAIL_URL + "application_type=" + application_type + "&application_no=" + application_no;
    }
}